import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;

import java.io.IOException;

public  class ADD extends Contronller{
    public static void Add(){
        GridPane pane = new GridPane();
        Scene scene = new Scene(pane);
        Stage stage = new Stage();
        stage.setScene(scene);
        stage.setTitle("添加员工");
        pane.setPrefSize(800, 600);
        pane.setVgap(15);
        pane.setHgap(10);
        Label label1 = new Label("姓名");
        Label label2 = new Label("性别");
        Label label3 = new Label("年龄");
        Label label4 = new Label("入职时间");
        Label label5 = new Label("住址");
        Label label6 = new Label("电话");
        Label label7 = new Label("工资");
        Label label8 = new Label("职位");
        label1.setPrefSize(80, 30);
        label2.setPrefSize(80, 30);
        label3.setPrefSize(80, 30);
        label4.setPrefSize(80, 30);
        label5.setPrefSize(80, 30);
        label6.setPrefSize(80, 30);
        label7.setPrefSize(80, 30);
        label8.setPrefSize(80, 30);
        pane.add(label1, 1, 1);
        pane.add(label2, 1, 3);
        pane.add(label3, 1, 5);
        pane.add(label4, 1, 7);
        pane.add(label5, 1, 9);
        pane.add(label6, 1, 11);
        pane.add(label7, 1, 13);
        pane.add(label8, 1, 15);
        TextField textField1 = new TextField();
        TextField textField2 = new TextField();
        TextField textField3 = new TextField();
        TextField textField4 = new TextField();
        TextField textField5 = new TextField();
        TextField textField6 = new TextField();
        TextField textField7 = new TextField();
        TextField textField8 = new TextField();
        textField1.setPrefSize(180, 30);
        textField2.setPrefSize(180, 30);
        textField3.setPrefSize(180, 30);
        textField4.setPrefSize(180, 30);
        textField5.setPrefSize(180, 30);
        textField6.setPrefSize(180, 30);
        textField7.setPrefSize(180, 30);
        textField8.setPrefSize(180, 30);
        pane.add(textField1, 3, 1);
        pane.add(textField2, 3, 3);
        pane.add(textField3, 3, 5);
        pane.add(textField4, 3, 7);
        pane.add(textField5, 3, 9);
        pane.add(textField6, 3, 11);
        pane.add(textField7, 3, 13);
        pane.add(textField8, 3, 15);
        Button Backbutton = new Button("返回");
        Backbutton.setPrefSize(80, 30);
        pane.add(Backbutton, 39, 0);
        Backbutton.setOnAction(event -> {stage.close();});
        Button determine = new Button("确定");
        determine.setPrefSize(80, 30);
        pane.add(determine, 39, 19);
        determine.setOnAction(event -> {
            String name=textField1.getText();
            String gender=textField2.getText();
            String age=textField3.getText();
            String time=textField4.getText();
            String address=textField5.getText();
            String phone=textField6.getText();
            String salary=textField7.getText();
            String position=textField8.getText();
            Main.staffList.add(new Staff(name,gender,age,time,address,phone,salary,position));
            stage.close();
            try {
                SAVERESOURCE.SaveResource();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            System.out.println("Suc");
        });
        stage.show();
    }
}
